package com.vt.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.ListMultimap;
import com.vt.admin.api.dto.CityTreeNodeOld;
import com.vt.admin.api.dto.DictDto;
import com.vt.admin.api.dto.TreeNode;
import com.vt.admin.api.entity.SysDictionary;
import com.vt.admin.service.SysDictService;
import com.vt.common.core.constant.CommonConstant;
import com.vt.common.core.util.R;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典
 */
@RestController
@RequestMapping("/dict")
@AllArgsConstructor
public class DictController {

    private SysDictService service;

    @GetMapping
    public IPage<SysDictionary> list(
            @RequestParam(defaultValue = CommonConstant.DEFAULT_PAGE) long page,
            @RequestParam(defaultValue = CommonConstant.DEFAULT_PAGE_SIZE) long pageSize,
            SysDictionary sysDictionary) {
        return service.list(page, pageSize, sysDictionary);
    }

    @ApiOperation("获取所有字典（简单格式）")
    @GetMapping("/simpleAll")
    public R<ListMultimap<String, DictDto>> findSimpleAll() {
        return service.findSimpleAll();
    }

    @ApiOperation("根据 type 查询")
    @GetMapping("/type/{type}")
    public List<SysDictionary.Simple> findByType(@PathVariable("type") String type) {
        return service.findByType(type);
    }

    @ApiOperation("城市树（到区）")
    @GetMapping("/cityTreeNode")
    public R<List<TreeNode>> cityTreeNode() {
        return service.cityTreeNode();
    }

    @ApiOperation("城市树（兼容一期）")
    @GetMapping("/cityTree")
    public List<CityTreeNodeOld> cityTree() {
        return service.cityTree();
    }
}
